<?php

namespace App\Remote\AMap\Track;

use Closure;
use Exception;
use Illuminate\Http\Response;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

class Remote extends \App\Remote\Remote
{
    static function getBaseUri(): string
    {
        // TODO: Implement getBaseUri() method.
        return "https://tsapi.amap.com";
    }

    /**
     * @return Closure
     * @throws Exception
     */
    public static function registerResponseHandle(): Closure
    {
        return function () {
            list($responseHttpCode, $responseOriginalContents) = func_get_args();
            if (isJson($responseOriginalContents) && $responseHttpCode == ResponseAlias::HTTP_OK) {
                $responseArrContents = json_decode($responseOriginalContents, true);
                if (attributeGet($responseArrContents, "errcode", null) == 10000) {
                    return $responseArrContents["data"];
                }
            }
            throw new Exception($responseOriginalContents);
        };
        // TODO: Change the autogenerated stub
    }

    /**
     * @param array $params
     * @return array
     */
    public static function withCommonHttpQueryParams(array $params = []): array
    {
        return array_merge(["key" => \App\Remote\AMap\Remote::getKey()], $params);
    }
}
